package com.example.musictutor.fragments.LevelSelectFrags;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import com.example.musictutor.R;
import com.example.musictutor.activities.PlaySongActivity;
import com.example.musictutor.domain.Song;
import com.example.musictutor.repository.facade.impl.SongDAOFacade;

import java.util.List;

/**
 * Created by ironhulk on 2014/05/11.
 */
public class LevelOneFragment extends Fragment implements View.OnClickListener{
    private View rootView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){

        rootView = inflater.inflate(R.layout.level_one_fragment, container, false);

        Button easySong = (Button)rootView.findViewById(R.id.btnLevel1Easy);
        Button mediumSong = (Button)rootView.findViewById(R.id.btnLevel1Medium);
        Button difficultSong = (Button)rootView.findViewById(R.id.btnLevel1Difficult);

        easySong.setOnClickListener(this);
        mediumSong.setOnClickListener(this);
        difficultSong.setOnClickListener(this);

        return rootView;
    }

    @Override
    public void onClick(View v) {

        // Get list of all songs
        SongDAOFacade dao = new SongDAOFacade(rootView.getContext());
        List<Song> songList = dao.getEntities();

        long one = songList.get(0).getId();
        long two = songList.get(1).getId();
        long three = songList.get(2).getId();

        switch(v.getId()){
            case R.id.btnLevel1Easy :
                Intent intent = new Intent(rootView.getContext(), PlaySongActivity.class);
                intent.putExtra("songId", one);
                startActivity(intent);
                break;
            case R.id.btnLevel1Medium:
                Intent intentTwo = new Intent(rootView.getContext(), PlaySongActivity.class);
                intentTwo.putExtra("songId", two);
                startActivity(intentTwo);
                break;
            case R.id.btnLevel1Difficult:
                Intent intentThree = new Intent(rootView.getContext(), PlaySongActivity.class);
                intentThree.putExtra("songId", three);
                startActivity(intentThree);
                break;
        }



    }
}